-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing environment as an argument to eng_r
#2358
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
knit_global()
is used in many places in this package. I guess this change is not enough.
I can provide an API to change the global environment (e.g., knit_global(envir)
to change to a custom envir
). Would that meet your need?
I think so? This change was sufficient for what I was trying to achieve, but I am obviously not as familiar with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now you can change the environment via knit_global(envir)
. I guess the good practice is to record the old envir, set the new envir, and restore the envir later, e.g.,
old_env = knit_global(new_env)
on.exit(knit_global(old_env), add = TRUE)
# do your stuff in new_env
I am trying to add a feature to my R package where each code chunk implements multiple analysis (and each analysis is executed in a separate environment). This presents some complications during knitting as every analysis is executed in the
global_env()
:knitr/R/block.R
Line 189 in fb1f423
I am wondering if it is possible to allow env be passed as an optional argument to
eng_r()
which defaults toglobal_env()
. I've made a PR (#) with the relevant changes, but please let me know if this creates other issues or if there is a better way of doing this.Thanks!